package com.entity;

import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wzm
 * @create 2023-06-16 10:27
 */
public class StudentResultSetHandler<T> implements ResultSetHandler<T> {

    @Override
    public T handle(ResultSet rs) throws SQLException {
        {
            List<Student> list = new ArrayList<>();
            Student student = null;
            //我们在这里使用jdbc的底层处理方式封装数据
            while(rs.next()){
                student = new Student(
                        rs.getInt(1),
                        rs.getString(2),
                        rs.getInt(3),
                        rs.getString(4),
                        rs.getInt(5),
                        rs.getInt(6 ),
                        new Grade(
                                rs.getInt(7),
                                rs.getString(8)
                        )
                );

                list.add(student);

            }
            return (T)list;
        }
    }
}
